
component  extends="ModelGlue.gesture.controller.Controller" output="false" beans="core"
{
	public ModelGlue.gesture.controller.Controller function init( required Any modelGlue){
		
		super.init( arguments.modelGlue );
		
		return this;
	}
	
	public ModelGlue.Core.Event function new( required Any event ){
		
		var service = beans.core.getService( 'Role' );
		var Role = service.new();
		
		Role.setIdRole( 0 );
		
		arguments.event.setValue( 'Role', Role );
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function save( required Any event ){
		
		var service = beans.core.getService( 'Role' );
		var Role = service.new();
		var preference = beans.core.getService( 'Preference' );
		var permission = beans.core.getService( 'Permission' );
		var validator = service.getValidator();
		
		arguments.event.makeEventBean( Role );
		
		Role.setPreferences( preference.createPreferenceList( arguments.event.getValue( 'preference' ), 'idPreference' ) );
		Role.setPermissions( permission.createPermissionList( arguments.event.getValue( 'permission' ), 'idPermission' ) );
		
		arguments.event.setValue( 'Role', Role );
		
		validator.validate( Role );
			
		if( validator.hasErrors() ){
		
			arguments.event.setValue( 'error', validator.getErrors() );
			
			arguments.event.setValue( 'errorBox', 'Role not saved.' );
			
			arguments.event.addResult( 'save.failure' );
		
		}else{
			
				service.saveRole( Role );
				
				arguments.event.setValue( 'successBox', 'Role saved.' );
				
				arguments.event.addResult( 'save.success' );
			
		}
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function get( required Any event ){
		
		var service = beans.core.getService( 'Role' );
		var Role = service.new();
		var result = "";
		
		arguments.event.makeEventBean( Role );
		
		result = service.getRole( Role );
									
		arguments.event.setValue( 'Role', result );
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function list( required Any event ){
		
		var service = beans.core.getService( 'Role' );
		var Role = service.new();
		var result = "";
		
		result = service.getRoles( Role );
									
		arguments.event.setValue( 'Role.list', result );
		
		return arguments.event;
	}

}
